package com.biz.factory;

import com.biz.handler.*;
import lombok.extern.slf4j.*;
import org.springframework.beans.factory.*;
import org.springframework.stereotype.*;

import javax.annotation.*;
import java.util.*;

/**
 * @Description
 *    数据归档工厂
 *    将所有实现了接口BackUpDataHandler的类加入静态Map中方便获取
 * @Author liuxi
 * @Date 2024/5/16
 **/
@Component
@Slf4j
public class BackUpDataFactory implements InitializingBean {

    @Resource
    private List<BackUpDataHandler> backUpDataHandlerList;

    private Map<String, BackUpDataHandler> handlerMap = new HashMap<>();

    public BackUpDataHandler getHandler(String scence) {
        return handlerMap.get(scence);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        backUpDataHandlerList.forEach((handler) -> {
            handlerMap.put(handler.getScence(), handler);
        });
    }

}
